package attributes;

import genetics.HaploidAttribute;

/**
 * 
 * @author Nicolas Winkler
 *
 */
public class Fleck extends HaploidAttribute {
	
	/**
	 * which percentage of the cow's skin is covered with a fleck
	 */
	public float fleckPercentage;
	
	/**
	 * the size of an average fleck
	 */
	public float fleckSize;
	
	/**
	 * the color of the flecks
	 */
	public int color;

	/**
	 * generates a random fleck attribute
	 */
	public Fleck() {
		dominantRecessive = Math.random() > 0.5 ? HaploidisizeType.DOMINANT : HaploidisizeType.RECESSIVE;
		fleckSize = (float) (Math.random() * 100.0);
	}

	@Override
	public HaploidAttribute mitosis() {
		Fleck newFleck = new Fleck();
		
		newFleck.dominantRecessive = this.dominantRecessive;
		
		newFleck.fleckPercentage = this.fleckPercentage
				* (1f + (float) Math.random() * 0.02f - 0.01f);
		newFleck.fleckSize = this.fleckSize
				* (1f + (float) Math.random() * 0.02f - 0.01f);
		newFleck.color = this.color;
		return newFleck;
	}

	@Override
	public HaploidAttribute intermediary(HaploidAttribute hb) {
		Fleck b;
		if (hb instanceof Fleck) {
			b = (Fleck) hb;
		}
		else {
			return null;
		}
		Fleck ret = new Fleck();
		ret.fleckPercentage = (fleckPercentage + b.fleckPercentage) / 2;
		return ret;
	}
}
